#encoding: utf-8
class Group < ActiveRecord::Base
  has_many :group_associations, :dependent => :delete_all
  has_many :members, :through => :group_associations
  has_many :groups_threads, :dependent => :delete_all
  has_many :feeds, {:as => :content, :dependent => :delete_all}
  
  has_one :section
  belongs_to :permission
  has_one :membership
  
  validates_presence_of :name

  before_create :generate_slug
  
  def generate_slug
  	slug = self.name.downcase
  	slug.gsub!('š','s')
  	slug.gsub!('đ','d')
  	slug.gsub!('č','c')
  	slug.gsub!('ć','c')
  	slug.gsub!('ž','z')
  	slug.gsub!(/[^a-z0-9\s]/, '') 
  	slug.gsub!(/\s+/,'-')
  	self.slug = slug
  end
   
  def url
  	return '/grupe/'+id.to_s+'/'+slug
  end
end
